package cn.ncu.service;

import cn.ncu.dao.CommentDao;
import cn.ncu.entity.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CommentServiceImpl implements CommentService{

    @Autowired
    private CommentDao commentDao;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Comment> findByPage(String articleid, Integer currentPage, Integer rows) {
        currentPage = currentPage == null ? 1 : currentPage;
        rows = rows == null ? 2 : rows;
        Integer start = (currentPage - 1) * rows;
        return commentDao.findByPage(articleid,start,rows);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public Integer findTotal(String articleid) {
        return commentDao.findTotal(articleid);
    }

    @Override
    public void saveComment(Comment comment) {
        commentDao.saveComment(comment);
    }
}
